/**
 * 
 */
package dbAccess;

import java.sql.*;
import exceptions.*;

/**
 * @author Anthares & Hennek
 *
 */
public class DBConnexionSingleton {
	public static Connection uniqueInstance;
	private static String dbUser = "sylmanager";
	
	public static Connection getInstance() throws PasIdentificationException{
		if (uniqueInstance == null) throw new PasIdentificationException();
		else return uniqueInstance;
	}
	
	public static void identification(String dbPass) throws ErreurIdentification, PasIdentificationException, BadLoginException, ODBCErrorException, BadPasswordException, DatabaseErrorException{
		if (uniqueInstance == null) {
			try {
				Class.forName("com.mysql.jdbc.Driver").newInstance();
				uniqueInstance = DriverManager.getConnection("jdbc:mysql://...:3306/syllabus", dbUser, dbPass);
				uniqueInstance.setAutoCommit(false);
			} catch (SQLException e) {
				throw new ErreurIdentification();
			} catch (ClassNotFoundException e) {
				throw new ODBCErrorException();
			} catch (InstantiationException e) {
				throw new ODBCErrorException();
			} catch (IllegalAccessException e) {
				throw new ODBCErrorException();
			}
		}
	}
}
